package org.lzy.shop.viewmodel.repository.lmpl

import org.lzy.shop.network.KtorApiService
import org.lzy.shop.response.CouponResponse
import org.lzy.shop.response.GoodsInfoResponse
import org.lzy.shop.response.GoodsSpecResponse
import org.lzy.shop.viewmodel.repository.BaseRepository
import org.lzy.shop.viewmodel.repository.GoodsRepository

class GoodsRepositoryImpl : BaseRepository(),GoodsRepository {

    override suspend fun getGoodsInfo(id: String): GoodsInfoResponse? {
        return safeApiCall {
            val response = KtorApiService.getGoodsInfo(id)
            handleResponse(response)
        }
    }

    override suspend fun getGoodsSpec(id: Int): MutableList<GoodsSpecResponse>? {
        return safeApiCall {
            val response = KtorApiService.getGoodsSpec(id.toString())
            handleResponse(response)
        }
    }

    override suspend fun getCoupon(): CouponResponse? {
        return safeApiCall {
            val response = KtorApiService.getCoupon()
            handleResponse(response)
        }
    }
}